package tryonce.controller;

import tryonce.entry.Store;
import tryonce.service.StoreService;
import java.util.Scanner;

public class StoreController {
    private StoreService service = new StoreService();
    private Scanner sc = new Scanner(System.in);
    public void start(){
        while (true){
            System.out.println("**********欢迎来到京东商城**********");
            System.out.println("1.添加商品");
            System.out.println("2.查看商品");
            System.out.println("3.查看指定商品");
            System.out.println("4.添加到购物车");
            System.out.println("5.查看购物车");
            System.out.println("6.退出");
            System.out.println("*********************************");
            System.out.println("请选择菜单：");
            int choice = sc.nextInt();
            switch (choice) {
                case 1-> addStore();
                case 2-> service.queryAll();
                case 3-> queryById();
                case 4-> addToCar();
                case 5-> service.showCart();
                case 6-> {
                    System.out.println("欢迎下次光临！");
                    System.exit(0);
                }
                default -> System.out.println("输入错误！");
            }
        }
    }
    //添加商品
    private void addStore() {
        System.out.println("请输入商品编号：");
        Integer id = sc.nextInt();
        System.out.println("请输入商品名称：");
        String name = sc.next();
        System.out.println("请输入商品价格：");
        Double price = sc.nextDouble();
        System.out.println("请输入商品颜色：");
        String color = sc.next();
        System.out.println("请输入商品尺寸：");
        Integer size = sc.nextInt();
        System.out.println("请输入商品数量：");
        Integer num = sc.nextInt();
        if (service.add(new Store(id, name, price, color, size, num))){
            System.out.println("添加成功");
        }else {
            System.out.println("添加失败，商品已存在");
        }
    }
    //查看指定编号商品
    private void queryById() {
        System.out.println("请输入商品编号：");
        service.queryById(sc.nextInt());
    }
    //添加到购物车
    private void addToCar() {
        System.out.println("请输入商品编号：");
        Integer id = sc.nextInt();
        System.out.println("请输入商品数量：");
        Integer num = sc.nextInt();
        System.out.println(service.addToCart(id,num));
    }
}
